Sum of Integers Up To N

For example: the sum of all the positive integers up to and including 5 is 1 + 2 + 3 + 4 + 5, which is 15. This is equal to 5 times 6, divided by 2; and it's also equal to 25 plus 5, divided by 2. And the sum of all the positive integers up to 100 is 100 times 101, divided by 2, or 10,000 + 100 divided by 2, either of which is 5,050.

The first sum can be thought of as 6 divided by 2 (6 being 5 + 1) times 5. And the second can be thought of as 50 times 101 (50 being 100 divided by 2, and 101 being 100 plus 1). What we've done here is to divide one of the two operands (n or n + 1) – whichever is even – by two first. In the first case, n is odd, so n + 1 is divisible by 2; in the second, n is even, so n itself is divisible by 2.

These two examples are both relatively easy. If you were asked (for example) the sum of all the positive integers up to 76, you'd probably still need a pencil and paper, or a calculator; but the answer is 38 times 77, which is 2,926.

© Haydn Thompson 2021